$(function () {
    $('#all_types').click(function () {
        $('#all_types_container').show();
        $('#all_type_logo').removeClass('glyphicon-chevron-down').addClass('glyphicon-chevron-up');
        $('#sorts_container').hide();
        $('#all_sorts_logo').removeClass('glyphicon-chevron-up').addClass('glyphicon-chevron-down');
    });
    $('#all_types_container').click(function () {
        $(this).hide();
        $('#all_type_logo').removeClass('glyphicon-chevron-up').addClass('glyphicon-chevron-down');
    });
    $('#all_sorts').click(function () {
        $('#sorts_container').show();
        $('#all_sorts_logo').removeClass('glyphicon-chevron-down').addClass('glyphicon-chevron-up');
        $('#all_types_container').hide();
        $('#all_type_logo').removeClass('glyphicon-chevron-up').addClass('glyphicon-chevron-down');
    });
    $('#sorts_container').click(function () {
        $(this).hide();
        $('#all_sorts_logo  ').removeClass('glyphicon-chevron-up').addClass('glyphicon-chevron-down');
    });

//    在商品页中点击+号，将商品添加到商品表中
    $('.addShopping').click(function () {
    //    获取到点击的标签，并获取到商品的id用于和服务端进行数据交互，因此html中要有记录商品id的属性
        var goods_tag = $(this);
        var goods_id =$(this).attr('goodsid');
        // console.log(goods_tag);
        // console.log(goods_id);
    //    向服务器发送ajax请求，修改数据库中信息
        $.getJSON('/axf/addcart/', {'goods_id': goods_id}, function (data) {
            // console.log(data);
            if(data['status'] == '910'){
                window.open('/axf/userlogin/', target='_self');
            }else if(data['status'] == '200'){
                //获取到数据库中当前商品的数量，显示出来
                var g_num = data['g_num'];
                //获取到显示商品数量的span标签
                var span = goods_tag.prev();
                span.html(g_num);
            }
        })
    });
    //在商品页中点击-号，数据库中做出相应的操作
    $('.subShopping').click(function () {
    //    获取到点击的标签，并获取到商品的id用于和服务端进行数据交互，因此html中要有记录商品id的属性
        var goods_tag = $(this);
        var goods_id =$(this).attr('goodsid');
        // console.log(goods_tag);
        // console.log(goods_id);
    //    向服务器发送ajax请求，修改数据库中信息
        $.getJSON('/axf/subcart/', {'goods_id': goods_id}, function (data) {
            // console.log(data);
            if(data['status'] == '910'){
                window.open('/axf/userlogin/', target='_self');
            }else if(data['status'] == '200'){
                //获取到数据库中当前商品的数量，显示出来
                var g_num = data['g_num'];
                //获取到显示商品数量的span标签
                var span = goods_tag.next();
                span.html(g_num);
            }else if(data['status'] == '911'){
                alert(data['msg']);
            }
        })
    })
});